package com.vctgo.evidence.controller;

import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.vctgo.common.core.utils.StringUtils;
import com.vctgo.evidence.domain.TbEvidence;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.vctgo.common.log.annotation.Log;
import com.vctgo.common.log.enums.BusinessType;
import com.vctgo.common.security.annotation.RequiresPermissions;
import com.vctgo.evidence.domain.TbEvi;
import com.vctgo.evidence.service.ITbEviService;
import com.vctgo.common.core.web.controller.BaseController;
import com.vctgo.common.core.web.domain.AjaxResult;
import com.vctgo.common.core.utils.poi.ExcelUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;

/**
 * 凭证子Controller
 *
 * @author vctgo
 * @date 2024-12-16
 */
@RestController
@RequestMapping("/evi")
public class TbEviController extends BaseController
{
    @Autowired
    private ITbEviService tbEviService;

    /**
     * 查询凭证子列表
     */
//    @RequiresPermissions("evidence:evi:list")
    @GetMapping("/list")
    public AjaxResult list(TbEvi tbEvi)
    {
        IPage<TbEvi> list = tbEviService.selectTbEviPage(tbEvi);
        return AjaxResult.success(list);
    }

    @GetMapping("/listById")
    public AjaxResult listById(Integer evidentId)
    {
        List<TbEvi> list = tbEviService.selectById(evidentId);
        return AjaxResult.success(list);
    }

    /**
     * 导出凭证子列表
     */
    @RequiresPermissions("evidence:evi:export")
    @Log(title = "凭证子", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbEvi tbEvi)
    {
        List<TbEvi> list = tbEviService.selectTbEviList(tbEvi);
        ExcelUtil<TbEvi> util = new ExcelUtil<TbEvi>(TbEvi.class);
        util.exportExcel(response, list, "凭证子数据");
    }

    /**
     * 获取凭证子详细信息
     */
    @RequiresPermissions("evidence:evi:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tbEviService.selectTbEviById(id));
    }

    /**
     * 新增凭证子
     */
//    @RequiresPermissions("evidence:evi:add")
//    @Log(title = "凭证子", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbEvi tbEvi)
    {
        return toAjax(tbEviService.insertTbEvi(tbEvi));
    }


    /**
     * 添加凭证模板
     */

    @PostMapping("/addModel")
    public AjaxResult addModel(@RequestBody TbEvidence tbEvidence)
    {

        return toAjax(tbEviService.addModel(tbEvidence));
    }

    /**
     * 修改凭证子
     */
    @RequiresPermissions("evidence:evi:edit")
    @Log(title = "凭证子", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbEvi tbEvi)
    {
        return toAjax(tbEviService.updateTbEvi(tbEvi));
    }

    /**
     * 删除凭证子
     */
    @RequiresPermissions("evidence:evi:remove")
    @Log(title = "凭证子", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tbEviService.deleteTbEviByIds(ids));
    }
}
